package com.iron.common.log.util;

import lombok.experimental.UtilityClass;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * LocalDateTime 工具类
 *
 * @author YT
 * @date 2019-06-28
 */
@UtilityClass
public class LocalDateUtils {

    /**
     * 将 Date 类类型转换为 LocalDateTime 类型
     *
     * @param date
     * @return
     */
    public static LocalDateTime UDateToLocalDateTime(Date date) {
        Instant instant = date.toInstant();
        ZoneId zone = ZoneId.systemDefault();
        return LocalDateTime.ofInstant(instant, zone);
    }

    /**
     * 将 long 类型的时间戳转换为 LocalDateTime 类型
     *
     * @param milli
     * @return
     */
    public static LocalDateTime longToLocalDateTime(Long milli) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        ZoneId zone = ZoneId.systemDefault();
        return LocalDateTime.ofInstant(Instant.ofEpochMilli(milli), zone);
    }
}
